package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.Dish;
import com.woniuxy.entity.DishCategory;
import com.woniuxy.entity.Shop;
import com.woniuxy.provider.DishCategoryProvider;
import com.woniuxy.provider.DishProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 菜品Mapper接口
 */
public interface DishMapper extends BaseMapper<Dish> {
    //按条件查询菜品列表（目前条件有菜品类别id和店铺id，配置文件位置provider/DishProvider.class）
    @SelectProvider(type = DishProvider.class,method = "select")
    @Result(column = "name",property = "dishName")
    List<Dish> getByCondition(Dish dish);

    //根据菜品id查询商铺信息
    @Select("select s.* from gfr_dish d,gfr_shop s where s.id = d.shopId and d.id = #{dishId}")
    Shop getShopByDishId(int dishId);


    @Select("select * from gfr_shop where name like '%${keyword}%'")
    Dish search(String keyword);

    @UpdateProvider(type = DishProvider.class,method = "update")
    void update(Dish dish);

    /**
     * 根据id删除规格,逻辑删除
     * @author wmy
     */
    @Update("update gfr_dish set status='n' where id=#{id}")
    void deleteById(int id);

    /**
     * 根据菜品id获取菜品
     * @param id
     * @return
     */
    @Select("select * from gfr_dish where id=#{id}")
    @Result(column = "spec_array",property = "spec_array")
    Dish getById(Integer id);
}
